package com.binfast.app.admin.controller;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.binfast.app.admin.services.LoginServ;
import com.binfast.bean.params.login.LoginDetailParam;
import com.binfast.common.util.Result;
import com.binfast.seed.annotation.IgnoreAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "")
public class LoginCtrl {
    private static final Log log = LogFactory.get();

    @Autowired
    LoginServ loginServ;

    @IgnoreAuth
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result findList(@Validated @RequestBody LoginDetailParam param) {
        return Result.success(loginServ.findOne(param));
    }

    @IgnoreAuth
    @GetMapping(value = "/userinfo")
    public Result getUserInfo(HttpServletRequest request) {
        String token = request.getHeader("token");
        return Result.success(loginServ.getUserInfo(token));
    }

}
